package com.edu.exam.enums;

/**
 * 题目附件类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum QuestionAttachmentType {
    IMAGE("IMAGE", "图片"),
    AUDIO("AUDIO", "音频"),
    VIDEO("VIDEO", "视频"),
    DOCUMENT("DOCUMENT", "文档"),
    ARCHIVE("ARCHIVE", "压缩包"),
    OTHER("OTHER", "其他");

    private final String code;
    private final String description;

    QuestionAttachmentType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 从代码创建枚举实例
     *
     * @param code 枚举代码
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static QuestionAttachmentType fromCode(String code) {
        for (QuestionAttachmentType type : QuestionAttachmentType.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的题目附件类型代码: " + code);
    }

    /**
     * 从描述创建枚举实例
     *
     * @param description 枚举描述
     * @return 对应的枚举实例
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static QuestionAttachmentType fromDescription(String description) {
        for (QuestionAttachmentType type : QuestionAttachmentType.values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("未知的题目附件类型描述: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}